#include "Packet.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

PACKET *makeNewPacket() {
	return (PACKET_HEADER *) calloc(1, sizeof(PACKET_HEADER));
}
PACKET *initPacket(PACKET_HEADER *head, PACKET_DATA *data) {
	PACKET *packet = makeNewPacket();
	packet->header = head;
	packet->data = data;
	return packet;
}
PACKET_HEADER *makeNewPacketHeader() {
	return (PACKET_HEADER *) calloc(1, sizeof(PACKET_HEADER));
}
PACKET_HEADER *initPacketHeader(unsigned long protocol,unsigned long msgType,unsigned long dataLen) {
	PACKET_HEADER *instance = makeNewPacketHeader();
	instance->protocol = protocol;
	instance->msgType = msgType;
	instance->dataLength = dataLen;
	return instance;
}
PACKET_DATA *makeNewPacketData() {
	return (PACKET_DATA *) calloc(1, sizeof(PACKET_DATA));
}
PACKET_DATA *init_MSG_LOGIN_REQ_DATA(char *message) {
	MSG_LOGIN_REQ_DATA *data = (MSG_LOGIN_REQ_DATA *) makeNewPacket();
	memcpy(data->id,message,16);
	memcpy(data->pwd,message+16,16);
	return (PACKET_DATA *) data;
}
PACKET_DATA *init_MSG_LOGIN_ACK_DATA(char *message) {
	MSG_LOGIN_ACK_DATA *data = (MSG_LOGIN_ACK_DATA *) makeNewPacket();
	memcpy(data->serverMessage,message,10);
	return (PACKET_DATA *) data;
}
